package com.bflow.web.controller.example;

import com.bflow.api.IBflowRunInstanceService;
import com.bflow.api.bo.BflowRunInstanceBo;
import com.bflow.api.bo.ext.BflowUserBo;
import com.bflow.util.AssertUtil;
import com.bflow.web.controller.BflowBaseController;
import com.bflow.web.util.TestLoginUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Name 模拟
 * @Author haowen
 * @Date 2019-01-03
 */
@Controller
@RequestMapping(value = "/bflow/test")
public class TestController extends BflowBaseController {


    @Autowired
    private IBflowRunInstanceService bflowRunInstanceService;

    /**
     * 启动流程
     * @param bo
     * @param req
     * @param resp
     * @return
     */
    @RequestMapping(value = "startProcess")
    @ResponseBody
    public String startProcess(BflowRunInstanceBo bo, HttpServletRequest req, HttpServletResponse resp) {
        try {
            BflowUserBo user = TestLoginUtil.getUser(req);
            AssertUtil.isNotNull(user, "您还未登录, 请先登录");
            bo.setStartUid(user.getUserId());
            bo.setStartUname(user.getUserName());
            bflowRunInstanceService.startProcess(bo);
            return returnOk("启动流程成功");
        } catch (Exception e) {
            return returnFail(e, "启动流程失败");
        }
    }


}
